/*
 * Copyright (c) 2010. Dylan Schell.
 */

package nl.xs4all.dylanschell.deckprinter.pages;

import com.google.inject.Inject;
import nl.xs4all.dylanschell.deckprinter.services.DeckPrinterConfig;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.Model;

import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: dylan
 * Date: Nov 21, 2010
 * Time: 7:49:38 PM
 * To change this template use File | Settings | File Templates.
 */
public class DecksPage extends BasePage
{
    @Inject
    public DeckPrinterConfig config;

    public DecksPage()
    {
        File deckFolder = config.getDeckFolder();

        RepeatingView rv = new RepeatingView("decks");
        add(rv);

        for (File f : deckFolder.listFiles())
        {
            WebMarkupContainer child = new WebMarkupContainer(rv.newChildId());
            rv.add(child);
            Link l = new Link<File>("deckLink", Model.of(f))
            {
                @Override
                public void onClick()
                {
                    setResponsePage(new DeckViewPage(getModelObject()));
                }
            };
            child.add(l);
            l.add(new Label("deckName", f.getName()));
        }
    }

    @Override
    public String getTitle()
    {
        return "Decks";
    }
}
